package com.photoeditor.demo.model.subscribe.manager;

import android.support.annotation.VisibleForTesting;

import com.billing.base.BillingManager;
import com.common.base.utils.DebugUtil;
import com.photoeditor.demo.app.TestUser;
import com.photoeditor.demo.model.preference.SPDataManager;

/**
 * Created by Lai on 2018/11/9 0009.
 */
public class AppVipManager {

    /**
     * 月费或年费
     * @return
     */
    public static boolean isVip() {
        return SPDataManager.isOneDayVip() || SPDataManager.getAdOneTimeVip() || isVipByType(SkuManager.TYPE_YEARLY, SkuManager.TYPE_MONTHLY);
    }

//    //模拟点击购买测试用
//    private static boolean isVip = false;
//    public static void enableVip() {
//        isVip = true;
//    }

    public static boolean isAdVip() {
        return isVip();
    }

    public static boolean isFaceAgingVip() {
        return isVip();
    }

    public static boolean isFutureBabyVip() {
        return isVip();
    }

    public static boolean isEthnicityVip() {
        return isVip();
    }

    public static boolean isFuturePredictorVip() {
        return isVip();
    }

    public static boolean isBeautyContestVip() {
        return isVip();
    }

    private static boolean isVipByType(int... types) {
        if (SPDataManager.getIsSvipSwithOn()) {
            if (TestUser.isTestUser()) {
                return true;
            }
        }
        if (types != null && types.length > 0) {
            for (int type : types) {
                String[] skuInfo = SkuManager.getSkuInfo(type);
                if (skuInfo != null) {
                    for (String sku : skuInfo) {
                        if (BillingManager.getInstance().isPurchased(sku)) {
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    }

    @VisibleForTesting
    private static boolean vip4Test() {
        return DebugUtil.isDebuggable();
    }

}
